home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.lib;
-
- import sub_arctic.lib.sub_arctic_error;
- import sub_arctic.output.loaded_image;
- import sub_arctic.output.drawable;
- import java.awt.Color;
- import java.util.Vector;
-
- /**
- * This the class that knows how to the display-side work of displaying
- * a horizontal scrollbar. It handles outputting a scrollbar from a
- * set of state variables.
- *
- * @author Scott Hudson
- */
- public class h_slider_display extends base_interactor {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This variable is a boolean which says if you want a box around the
- * slider or not.
- */
- protected boolean _boxed=true;
-
- /**
- * Return whether or not the user wants a box around the slider or
- * not.
- * @return boolean true if the user wants the slider boxed
- */
- public boolean boxed(){ return _boxed;};
-
- /**
- * Modify whether or not to box the slider.
- *
- * @param boolean b the new boxed state variable
- */
- public void set_boxed(boolean b) {
- _boxed=b;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* this is here so subclasses can draw the thumb at places other than
- * against the top edge of the interactor. This is a shift in the *Y*
- * direction. */
-
- /**
- * This variable is how much to offset (in y and in pixels) the slider's
- * thumb by when drawing it.
- */
- protected int _thumb_shift=0;
-
- /**
- * Return how much to shift the thumb by (in y, and in pixels).
- * @return int how much to shift the thumb by (in y, and in pixels).
- */
- public int thumb_shift() { return _thumb_shift;}
-
- /**
- * Change the amount to shift the thumb by (in the y direction)
- * @param int v the amount to shift the thumb by in pixels
- */
- public void set_thumb_shift(int v) {
- _thumb_shift=v;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Image for the right button */
- protected loaded_image _right_img;
-
- /**
- * Image for the right button
- *
- * @return the right image.
- */
- public loaded_image right_img() {return _right_img;}
-
- /**
- * Set the image for the right button
- *
- * @param loaded_image img the image to use for the right button.
- */
- public void set_right_img(loaded_image img) {
- _right_img = img;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Image for the left button */
- protected loaded_image _left_img;
-
- /**
- * Image for the left button
- *
- * @return the left image.
- */
- public loaded_image left_img() {return _left_img;}
-
- /**
- * Set the image for the left button
- *
- * @param loaded_image img the image to use for the left button
- */
- public void set_left_img(loaded_image img) {
- _left_img = img;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Image for the "thumb" */
- protected loaded_image _thumb_img;
-
- /**
- * Image for the thumb
- *
- * @return the thumb image.
- */
- public loaded_image thumb_img() {return _thumb_img;}
-
- /**
- * Set the image for the thumb of the slider
- *
- * @param loaded_image img the image to use for the slider's thumb
- */
- public void set_thumb_img(loaded_image img) {
- _thumb_img = img;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Image for the background -- use null for a default solid color */
- protected loaded_image _back_img;
-
- /**
- * Image for the background (pattern). You'll get null for a default
- * solid color.
- *
- * @return the background image
- */
- public loaded_image back_img() {return _back_img;}
-
- /**
- * Set the image for the background -- use null for a default solid color
- *
- * @param loaded_image img the image for the background of the slider
- */
- public void set_back_img(loaded_image img) {
- _back_img = img;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Minimum value of the slider */
- protected int _min_val;
-
- /** Minimum value of the slider
- * @return int the minimum value of the slider */
- public int min_val() {return _min_val;}
-
- /**
- * Set the minimum value of the slider
- *
- * @param int val the new minimum value of the slider.
- */
- public void set_min_val(int val) {
- _min_val = val;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Maximum value of the slider */
- protected int _max_val;
-
- /** Maximum value of the slider
- * @return the maximum value of the slider*/
- public int max_val() {return _max_val;}
-
- /**
- * Set the maximum value of the slider
- *
- * @param int val the new maximum value of the slider.
- */
- public void set_max_val(int val) {
- _max_val = val;
- damage_self();
- }
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Small increment value */
- protected int _small_inc;
-
- /**
- * Return the small increment value (this is the amount the slider's
- * value changes when you push the end buttons).
- *
- * @return int the small increment value of the slider
- */
- public int small_inc() {return _small_inc;}
-
- /**
- * Set the small increment value (amount the value changes when you click on
- * the end buttons.
- *
- * @param int val the new small increment
- */
- public void set_small_inc(int val) {_small_inc = val;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Large increment value */
- protected int _large_inc;
-
- /**
- * Return the large increment value (this is the amount the slider's
- * value changes when you click in the thumb area but not on the thumb).
- *
- * @return int the large increment value of the slider
- */
- public int large_inc() {return _large_inc;}
-
- /**
- * Set the large increment value (amount the value changes when you
- * click on the thumb area but not on the thumb).
- *
- * @param int val the new small increment
- */
- public void set_large_inc(int val) {_large_inc = val;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return the value of the part_a component of this object. In our case
- * this is stored in _value.
- * @return int the up to date value of part_a (which is tied to _value).
- */
- public int part_a()
- {
- /* Make sure its up to date and in range then return it */
- eval_part_a();
- conform();
- return _value;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set part_a value directly bypassing the constraint system (but doing
- * damage). This should normally only be done by the constraint system
- * or some other part of the system which takes care of marking things
- * out-of-date, etc. itself. In this case part_a is stored in _value.
- *
- * @param int v the new value for part_a (AKA _value).
- */
- protected void set_raw_part_a(int v)
- {
- /* don't do anything unless this is a change */
- if (v != _value)
- {
- /* make change and do damage */
- _value = v;
- conform();
- damage_self();
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set the part_a component of this object. In our case this is stored in
- * _value.
- *
- * @param int v the new value for part_a (AKA _value).
- */
- public void set_part_a(int v)
- {
- /* if this has a constraint throw an exception */
- if ((active_constraints() & PART_A) != 0)
- throw new sub_arctic_error(
- "Attempt to assign value to constrained part_a " +
- "(AKA h_slider_display.value)");
-
- /* don't do anything unless this is a change */
- if (v != _value)
- {
- set_raw_part_a(v);
- mark_part_a_ood();
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Current value of the slider */
- protected int _value;
-
- /**
- * Current value of the slider
- *
- * @return int the current value of this slider
- */
- public int value() {return part_a();}
-
- /**
- * Set current value of the slider. This value will be forced to be
- * between the min and the max, inclusive.
- *
- * @param int val the new value
- */
- public void set_value(int val)
- {
- set_part_a(val);
- }
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Full constructor for the h_slider_display. If you do not supply
- * an image for any of the image slots (i.e. you pass null) a default
- * look will be applied for you.
- *
- * @param int xv x position of the slider.
- * @param int yv y position of the slider.
- * @param int wv width of the slider (in pixels).
- * @param int minv minimum value of the slider.
- * @param int maxv maximum value of the slider.
- * @param int init_val initial value of the slider.
- * @param int sincv small increment value.
- * @param int lincv large increment value.
- * @param loaded_image rt_im image for the right button.
- * @param loaded_image lf_im image for the left button.
- * @param loaded_image th_im image for the thumb.
- * @param loaded_image back_pat image for the background of the slider.
- */
- public h_slider_display(
- int xv, int yv, int wv,
- int minv, int maxv,
- int init_val,
- int sincv, int lincv,
- loaded_image rt_im, loaded_image lf_im, loaded_image th_im,
- loaded_image back_pat)
- {
- /* let the superclass init (with dummy temporary width) */
- super(xv,yv, wv, 15);
-
- /* initialize locals */
- _min_val = minv; _max_val = maxv;
- _value = init_val;
- _small_inc = sincv; _large_inc = lincv;
-
- _right_img = rt_im; _left_img = lf_im; _thumb_img = th_im;
- _back_img = back_pat;
-
- /* use defaults for any nulls */
- if (_right_img == null) _right_img = std.h_slider_right();
- if (_left_img == null) _left_img = std.h_slider_left();
- if (_thumb_img == null) _thumb_img = std.h_slider_thumb();
- if (_back_img == null) _back_img = std.h_slider_back();
-
- /* now reset the height to the real height */
- int max_h = 0;
- if (max_h < _right_img.height()) max_h = _right_img.height();
- if (max_h < _left_img.height()) max_h = _left_img.height();
- if (max_h < _thumb_img.height()) max_h = _thumb_img.height();
- set_intrinsic_h(max_h);
-
- /* make sure values are all in range and in order */
- conform();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a new h_slider_display with the artkit look.
- *
- * @param int xv x position of the slider.
- * @param int yv y position of the slider.
- * @param int wv width of the slider (in pixels).
- * @param int minv minimum value of the slider.
- * @param int maxv maximum value of the slider.
- * @param int init_val initial value of the slider.
- * @param int sincv small increment value.
- * @param int lincv large increment value.
- */
- public h_slider_display(
- int xv, int yv, int wv,
- int minv, int maxv,
- int init_val,
- int sincv, int lincv)
- {
- this(xv,yv,wv,minv,maxv,init_val,sincv,lincv, null, null, null, null);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Make sure min <= max and min <= value <= max by forcing value in range.
- */
- protected void conform()
- {
- int t;
-
- /* make sure min, max are still ok */
- if (_min_val > _max_val)
- {
- t = _min_val; _min_val = _max_val; _max_val = t;
- }
-
- /* force value in range */
- if (_value < _min_val) {_value = _min_val;}
- if (_value > _max_val) {_value = _max_val;}
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Indicate that we intrinsically constrain height, but not part_a.
- * @return int bitset indicating parts we intrinsically constrain.
- */
- public int intrinsic_constraints()
- {
- return (super.intrinsic_constraints() & ~PART_A) | H;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Compute the offset to the thumb in pixels (returns -1 for no thumb)
- *
- * @return int the amount the thumb should be shifted right to account for
- * the value of the slider
- */
- protected int thumb_offset()
- {
- int off, slide_range, value_range;
-
- /* compute ranges for thumb */
- slide_range = w() - _right_img.width() - _left_img.width()
- - _thumb_img.width();
- value_range = max_val() - min_val();
-
- /* return negative if there is no room for the thumb */
- if (slide_range < 0 || value_range < 0) return -1;
- /*
- * Check to keep from getting a divide by zero exception below.
- * If we just fit, return a zero offset.
- */
- if (slide_range == 0 || value_range == 0) return 0;
-
- /* otherwise compute drawing offset for thumb */
- off = (value() - min_val()) * slide_range / value_range;
- if (off < 0) off = 0;
- if (off > slide_range) off = slide_range;
-
- return off;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Draw the current image on the drawable provided.
- *
- * @param drawable d a drawable for the image or screen you want this
- * object drawn on
- */
- protected void draw_self_local(drawable d)
- {
- int off;
-
- /* fill the rectangle behind the slider */
- if (_back_img != null)
- {
- d.tileImage(_back_img, 0,0,w()-1, h()-1);
- }
-
- /* compute offset for thumb */
- off = thumb_offset();
-
- /* draw the thumb if we have room for one */
- if (off >= 0)
- {
- d.drawImage(_thumb_img, _left_img.width()+off, thumb_shift());
- }
-
- /* draw the buttons */
- d.drawImage(_left_img, 0,0);
- d.drawImage(_right_img, w()-_right_img.width(),0);
-
- /* draw a box around the whole thing if that flag is set
- * (which it is by default) */
- if (boxed()) {
- d.setColor(Color.black);
- d.drawRect(0,0, w()-1,h()-1);
- }
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-